
public class Array012
{

    public static int list[] = {0,1,1,0,2};
    /**
     * @param args
     */
    public  static void printList() {
	for(int i = 0; i< list.length ;i++) {
	    System.out.print(list[i]+" ");
	}
    }
    
    public static void sortArray(){
	int l=0,m=0,h=list.length-1;
	while(m<list.length){
	    int temp;
		System.out.println(l+" "+m+" "+h+" "+list[m]);
		printList();
	    switch(list[m]){
	
		case 0:
		    temp = list[m];
		    list[m]=list[l];
		    list[l]=temp;
		    m++;l++;
		    break;
		case 1:
		    m++;
		    break;
		case 2:
		    temp = list[m];
		    list[m]=list[h];
		    list[h]= temp;
		    h--;
		    break;
		  }
	}
    }

    public static void main(String[] args)
    {
	System.out.println("Before sorting");
	printList();
	sortArray();
	System.out.println("\nAfter sorting");
	printList();

    }

}
;